from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms

image_path = "train/ants/0013035.jpg"
img_PIL = Image.open(image_path)#Alt+Enter导入包
#ToTensor
tensor_trans = transforms.ToTensor()#实例化工具
img_tensor = tensor_trans(img_PIL)
#Normalize
normal_trans = transforms.Normalize([0.5,0.5,0.5],[0.5,0.5,0.5])
img_normal = normal_trans(img_tensor)
#Resize
resize_trans_1 = transforms.Resize((256,256))
resize_trans_2 = transforms.Resize(512)
img_resize1 = resize_trans_1(img_tensor)
# img_resize2 = resize_trans_2(img_PIL)
#compose
compose_trans = transforms.Compose([resize_trans_2,tensor_trans])
img_resize2 = compose_trans(img_PIL)
writer = SummaryWriter("logs")
writer.add_image("Tensor_img",img_resize2,4)
writer.close()
